﻿Imports Autodesk.AutoCAD.ApplicationServices
Public Class CLDS_Network_Container
    Private _CA As CLDS_ACAD
    Private _CRColour As System.Drawing.Color
    Private _PS As Autodesk.AutoCAD.Windows.Palette
    Private _Context As String
    Private _VObject As Autodesk.AutoCAD.DatabaseServices.ObjectId = Nothing
    Private _Changed As Boolean = False
    Private _Props As CLDS_Segment_Properties = Nothing
    Private _MTCounts As Collection = Nothing
    Private _MTShow As Boolean = False
    Private _MTChanged As Boolean = False
    Private _MTProps As CLDS_MTSegment_Properties = Nothing
    Private nnItem As ListViewItem
    Private nnX As Integer
    Friend WithEvents editbox As TextBox
    Dim subitemselected As Integer
    Dim subitemtext As String
    Dim saveitemtext As String
    Public Property CA() As CLDS_ACAD
        Get
            Return _CA
        End Get
        Set(ByVal value As CLDS_ACAD)
            _CA = value
        End Set
    End Property
    Public Property VObject() As Autodesk.AutoCAD.DatabaseServices.ObjectId
        Get
            Return _VObject
        End Get
        Set(ByVal value As Autodesk.AutoCAD.DatabaseServices.ObjectId)
            _VObject = value
        End Set
    End Property
    Public Property Changed() As Boolean
        Get
            Return _Changed
        End Get
        Set(ByVal value As Boolean)
            _Changed = value
        End Set
    End Property
    Public Property Props() As CLDS_Segment_Properties
        Get
            Return _Props
        End Get
        Set(ByVal value As CLDS_Segment_Properties)
            _Props = value
        End Set
    End Property
    Public Property MTChanged() As Boolean
        Get
            Return _MTChanged
        End Get
        Set(ByVal value As Boolean)
            _MTChanged = value
        End Set
    End Property
    Public Property MTProps() As CLDS_MTSegment_Properties
        Get
            Return _MTProps
        End Get
        Set(ByVal value As CLDS_MTSegment_Properties)
            _MTProps = value
        End Set
    End Property
    Public Property Context() As String
        Get
            Return _Context
        End Get
        Set(ByVal value As String)
            _Context = value
        End Set
    End Property
    Public Property MTCounts() As Collection
        Get
            Return _MTCounts
        End Get
        Set(ByVal value As Collection)
            _MTCounts = value
        End Set
    End Property
    Public Sub Initialize(ByVal p_CA As CLDS_ACAD, Optional ByVal p_context As String = "DWG", Optional ByVal p_first As Boolean = True)
        Me._CA = p_CA
        If p_first Then
            editbox = New TextBox
            editbox.Size = New Size(0, 0)
            editbox.Location = New Point(0, 0)
            Me.lvNNodes.Controls.Add(editbox)
            editbox.Hide()
            Me._Context = p_context
        End If
        Dim cYN As Collection = New Collection()
        cYN.Add("Y")
        cYN.Add("N")
        CLDS_YN_Prop_Converter.YNList = cYN
        Dim cAType As Collection = _CA.CLDS_PopulateCollection("PR", "AY", "CODE")
        _CA.CLDS_PopulateCB(Me.cbFAType, cAType)
        If cAType.Count = 1 Then
            Me.lbFArea.Visible = True
            Me.cbFAType.Visible = False
        Else
            Me.lbFArea.Visible = False
            Me.cbFAType.Visible = True
        End If
        Me.cbFAType.SelectedIndex = 0
        Dim cArea As Collection = _CA.CLDS_PopulateCollection("AR", "AR", "CODE")
        CLDS_Area_Prop_Converter.AreaList = cArea
        _CA.CLDS_PopulateCB(Me.cbDArea, cArea)
        _CA.CLDS_PopulateCB(Me.cbFArea, cArea, "-")
        Dim cSeg As Collection = _CA.CLDS_PopulateCollection("SC", "SC", "SEGREGATION")
        CLDS_Seg_Prop_Converter.SegList = cSeg
        _CA.CLDS_PopulateCB(Me.cbDSeg, cSeg)
        _CA.CLDS_PopulateCB(Me.cbFSeg, cSeg, "-")
        'Dim cSgN As Collection = _CA.CLDS_PopulateCollection("SC", "CB", "SEGREGATION")
        '_CA.CLDS_PopulateCB(Me.cbFSeg, cSgN, "-")
        Dim cTyp As Collection = _CA.CLDS_PopulateCollection("NT", "NT", "NRTYPE")
        CLDS_Type_Prop_Converter.TypeList = cTyp
        _CA.CLDS_PopulateCB(Me.cbDType, cTyp)
        Dim cPS As Collection = _CA.CLDS_PopulateCollection("NT", "PS", "NRTYPE")
        CLDS_Type_Prop_Converter.PSList = cPS
        _CA.CLDS_PopulateCB(Me.cbDPSType, cPS)
        If cPS Is Nothing OrElse cPS.Count = 0 Then
            Me.rbAddPS.Checked = False
            Me.rbAddPS.Enabled = False
        Else
            Me.rbAddPS.Enabled = True
        End If
        _MTCounts = _CA.CLDS_PopulateCollection("NT", "MT", "TIERCOUNT", "NRTYPE")
        If _CA.pTokens("PD_ANALYSIS") = "N" Then
            Me.cbShowAnalysis.Visible = False
            Me.cbShowAnalysis.Checked = False
        Else
            Me.cbShowAnalysis.Visible = True
        End If
        Dim av As String = Me.cbFArea.Text
        Dim sv As String = Me.cbFSeg.Text
        If ((av = "-" Or av = "") And (sv = "-" Or sv = "")) Or Me.cbShowAnalysis.Checked Then
            Me.btPClear.Enabled = False
        Else
            Me.btPClear.Enabled = True
        End If
        _CA.CLDS_GetAssocAreas(Me._Context, Me.lvDwgAreas)
    End Sub

    Private Sub btDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btDraw.Click
        Dim id As String = Microsoft.VisualBasic.FileIO.FileSystem.GetName(Application.DocumentManager.MdiActiveDocument.Name)
        Dim ay As String = Mid$(Me.cbFAType.Text, 1, 1)
        id = Mid$(id, 1, InStr(id, ".") - 1)
        id = "DWG=""" & id & """"
        If Me.cbShowAnalysis.Checked Then
            id = id & " ANALYSIS=""Y"""
            id = id & " FOCUS=""" & _CA.pProps.v_focus & """"
            If Me.cbFArea.Text <> "-" Then
                id = id & " SCOPE=""" & ay & """"
                id = id & " AREA=""" & Me.cbFArea.Text & """"
            End If
            If Me.cbFSeg.Text <> "-" Then
                id = id & " SEG=""" & Me.cbFSeg.Text & """"
            End If
        Else
            If Me.cbShowFill.Checked Then
                If Me.tbHFill.Text = "" Then
                    id = id & " FILL=""Y"""
                Else
                    id = id & " FILL=""" & Me.tbHFill.Text & """"
                End If
            End If
            If Me.cbShowLock.Checked Then
                id = id & " LOCK=""Y"""
            End If
            If Me.cbFArea.Text <> "-" Then
                id = id & " SCOPE=""" & ay & """"
                id = id & " AREA=""" & Me.cbFArea.Text & """"
            End If
            If Me.cbFSeg.Text <> "-" Then
                id = id & " SEG=""" & Me.cbFSeg.Text & """"
            End If
        End If
        If Not Me.cbFDevice.Checked Then
            id = id & " DEVICE=""N"""
        End If

        _CA.CLDS_DrawNetwork(_Context, id, Me.tbNCount, Me.tbSCount, Me.tbDCount)
        Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen()
    End Sub

    Private Sub btClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btClear.Click
        _CA.CLDS_EraseEntireNetwork(Me.tbNCount, Me.tbSCount, Me.tbDCount)
        _CA.CLDS_RouteClearAll(_CA.pRouteDialog)
        _CA.CLDS_ClearHighlights()
        _CA.DeallocateAll()
        Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen()
    End Sub
    Private Sub btPClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btPClear.Click
        Dim id As String = Microsoft.VisualBasic.FileIO.FileSystem.GetName(Application.DocumentManager.MdiActiveDocument.Name)
        Dim ay As String = Mid$(Me.cbFAType.Text, 1, 1)
        id = Mid$(id, 1, InStr(id, ".") - 1)
        id = "DWG=""" & id & """"
        If Me.cbFArea.Text <> "-" Then
            id = id & " SCOPE=""" & ay & """"
            id = id & " AREA=""" & Me.cbFArea.Text & """"
        End If
        If Me.cbFSeg.Text <> "-" Then
            id = id & " SEG=""" & Me.cbFSeg.Text & """"
        End If
        If Not Me.cbFDevice.Checked Then
            id = id & " DEVICE=""N"""
        End If
        _CA.CLDS_RouteClearAll(_CA.pRouteDialog)
        _CA.CLDS_ClearHighlights()
        _CA.CLDS_ErasePartialNetwork(_Context, id, Me.tbNCount, Me.tbSCount, Me.tbDCount)
        Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen()
        '_CA.DeallocateAll()
    End Sub

    Private Sub btCRShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        _CA.CLDS_RouteDialog("")
    End Sub
    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
    End Sub
    Public Sub ShowDevice()
        Dim dev As String = ""
        If Me.tbDevID.Text = "" Then
            Me.tbDevID.Text = ""
            Me.tbDesc.Text = ""
            Me.tbSystem.Text = ""
            Me.tbArea.Text = ""
            Me.gbDevice.Update()
            _CA.CLDS_DeviceDetail(Me, Me.tbDevID.Text)
            Me.gbDevice.Update()
        Else
            _CA.CLDS_DeviceDetail(Me, Me.tbDevID.Text)
            Me.tbDevID.ReadOnly = True
        End If
    End Sub
    Private Sub btExeqry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btExeqry.Click
        Dim dev As String = ""
        If Me.tbDevID.Text = "" Then
            Me.tbDevID.Text = ""
            Me.tbDesc.Text = ""
            Me.tbSystem.Text = ""
            Me.tbArea.Text = ""
            Me.gbDevice.Update()
            _CA.CLDS_DeviceDetail(Me, Me.tbDevID.Text)
            Me.gbDevice.Update()
            _CA.CLDS_PickDevice(dev)
            If Not (dev = "") Then
                Me.tbDevID.Text = dev
                Me.gbDevice.Update()
                _CA.CLDS_DeviceDetail(Me, Me.tbDevID.Text)
                Me.tbDevID.ReadOnly = True
            End If
        Else
            _CA.CLDS_DeviceDetail(Me, Me.tbDevID.Text)
            Me.tbDevID.ReadOnly = True
        End If
    End Sub

    Private Sub lvNNodes_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvNNodes.SelectedIndexChanged
        Dim lv As ListView = DirectCast(sender, ListView)
        If lv.SelectedItems.Count = 1 Then
            Dim lvi As ListViewItem = lv.SelectedItems.Item(0)
            CA.CLDS_SelectNode(lvi.Text, Me.tbDevID.Text)
        Else
            CA.CLDS_SelectNode("")
        End If
    End Sub
    Private Sub DeleteNNode()
        Dim lvi As ListViewItem = Nothing
        Dim nn As String = ""
        Dim nu As Integer = 0
        If Me.lvNNodes.SelectedItems.Count = 1 Then
            lvi = Me.lvNNodes.SelectedItems.Item(0)
            nn = lvi.Text
            nu = Val(lvi.SubItems.Item(4).Text)
        End If
        If nn = "" Then
            MsgBox("No near-node selected")
        Else
            If nu > 0 Then
                MsgBox("Device node " & nn & " in use by " & nu & " cables", MsgBoxStyle.Critical, "CMPIC AutoCAD")
                Exit Sub
            End If
            If lvi.Group.Name = "Deleted" Then
                lvi.Group = lvi.ListView.Groups("Updated")
                CA.CLDS_ShowOffRoute(Me.tbDevID.Text, nn, 0, True)
            ElseIf lvi.Group.Name = "New" Then
                lvi.Remove()
                CA.CLDS_ShowOffRoute(Me.tbDevID.Text, nn, 0, False)
            Else
                lvi.Group = lvi.ListView.Groups("Deleted")
                CA.CLDS_ShowOffRoute(Me.tbDevID.Text, nn, 0, False)
            End If
            lvi.Selected = True
        End If
    End Sub
    Private Sub lvNNodes_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvNNodes.DoubleClick
        Dim nstart As Integer = nnX
        Dim spos As Integer = 0
        Dim epos As Integer = Me.lvNNodes.Columns(0).Width
        Dim i As Integer
        For i = 0 To Me.lvNNodes.Columns.Count - 1
            If nstart > spos And nstart < epos Then
                subitemselected = i
                Exit For
            End If
            spos = epos
            epos += Me.lvNNodes.Columns(i + 1).Width
        Next
        If subitemselected <> 2 Then            ' Only off-route length can be edited
            Exit Sub
        End If
        If nnItem.SubItems(4).Text <> "0" Then  ' Only unused near-nodes can be updated
            Exit Sub
        End If
        If nnItem.Group.Name = "Deleted" Then   ' Only undeleted near-nodes can be updated
            Exit Sub
        End If
        subitemtext = nnItem.SubItems(subitemselected).Text
        saveitemtext = subitemtext
        editbox.Size = New Size(epos - spos, nnItem.Bounds.Bottom - nnItem.Bounds.Top)
        editbox.Location = New Point(spos + nnItem.Bounds.X, nnItem.Bounds.Y)
        editbox.CharacterCasing = CharacterCasing.Upper
        editbox.Show()
        editbox.Text = subitemtext
        editbox.SelectAll()
        editbox.Focus()
    End Sub

    Private Sub lvNNodes_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lvNNodes.MouseDown
        nnItem = Me.lvNNodes.GetItemAt(e.X, e.Y)
        nnX = e.X
    End Sub
    Private Sub editbox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles editbox.KeyDown
        If e.KeyCode = Keys.Enter Then
            'nnItem.SubItems(subitemselected).Text = editbox.Text
            saveitemtext = editbox.Text
            editbox.Hide()
        End If
        If e.KeyCode = Keys.Escape Then
            'nnItem.SubItems(subitemselected).Text = saveitemtext
            editbox.Hide()
        End If
    End Sub
    Private Sub editbox_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles editbox.Leave
        'nnItem.SubItems(subitemselected).Text = editbox.Text
        If saveitemtext = "" Then
            saveitemtext = "0.0"
        End If
        If nnItem.SubItems(subitemselected).Text <> saveitemtext Then
            nnItem.SubItems(subitemselected).Text = saveitemtext
            If nnItem.Group.Name = "Existing" Then
                nnItem.Group = nnItem.ListView.Groups("Updated")
            End If
        End If
        editbox.Hide()
    End Sub
    Private Sub editbox_PreviewKeyDown(ByVal sender As Object, ByVal e As PreviewKeyDownEventArgs) Handles editbox.PreviewKeyDown
        If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Escape Then
            e.IsInputKey = True
        End If
    End Sub
    Private Sub numericTextboxKeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _
        Handles editbox.KeyPress, tbDZ.KeyPress, tbHFill.KeyPress
        Dim tb As TextBox = CType(sender, TextBox)
        Dim chr As Char = e.KeyChar
        'If IsNumeric(e.KeyChar) And Not e.KeyChar = "-" Then
        If IsNumeric(e.KeyChar) Then
            'If adding the character to the end of the current TextBox value results in
            ' a numeric value, go on. Otherwise, set e.Handled to True, and don't let
            ' the character to be added.
            e.Handled = Not IsNumeric(tb.Text & e.KeyChar)
        ElseIf e.KeyChar = "." Then
            'For the decimal character (.) we need a different rule:
            'If adding a decimal to the end of the current value of the TextBox results
            ' in a numeric value, it can be added. If not, this means we already have a
            ' decimal in the TextBox value, so we only allow the new decimal to sit in
            ' when it is overwriting the previous decimal.
            If Not (tb.SelectedText = "." Or IsNumeric(tb.Text & e.KeyChar)) Then
                e.Handled = True
            End If
        ElseIf e.KeyChar = "-" Then
            If UCase(tb.Name) = "TBDZ" Then ' Only elevation field allows negative values
                'A negative sign is prevented if the "-" key is pressed in any location
                ' other than the begining of the number, or if the number already has a
                ' negative sign
                If tb.SelectionStart <> 0 Or Microsoft.VisualBasic.Left(tb.Text, 1) = "-" Then
                    e.Handled = True
                End If
            Else
                e.Handled = True
            End If
        ElseIf Not Char.IsControl(e.KeyChar) Then
            'IsControl is checked, because without that, keys like BackSpace couldn't
            ' work correctly.
            e.Handled = True
        End If
    End Sub

    Private Sub btDelNN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btDelNN.Click
        DeleteNNode()
    End Sub

    Private Sub btAddNN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btAddNN.Click
        CA.CLDS_AddNearNode(Me)
    End Sub

    Private Sub btCommit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btCommit.Click
        CA.CLDS_SaveNearNodes(Me)
    End Sub

    Private Sub tbEntqry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbEntqry.Click
        Me.tbDevID.ReadOnly = False
        Me.tbDevID.Text = ""
        CA.CLDS_DeviceDetail(Me, "")
    End Sub

    Private Sub btAddNode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btAddNode.Click
        CA.CLDS_CreateNode(Me, _Context, Me.rbAddPS.Checked, Me.rbAddDevice.Checked, "")
    End Sub


    Private Sub btPLNodes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btFollow.Click
        CA.CLDS_CreatePLNodes(Me, _Context, Me.rbAddPS.Checked, CA.pPrefs.x_dlpl, "")
    End Sub


    Private Sub btUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btUpload.Click
        CA.CLDS_Upload(Me, Me._Context)
    End Sub

    Private Sub btDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btDelete.Click
        CA.CLDS_DeleteMultiSegment(Me)
    End Sub

    Private Sub btUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btUpdate.Click
        CA.CLDS_ShowMultiNetworkProperties(Me)
        _MTShow = False
    End Sub

    Private Sub cbDArea_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbDArea.SelectedIndexChanged
        Dim cb As ComboBox = DirectCast(sender, ComboBox)
        If cb.SelectedIndex < 0 Then
            cb.SelectedIndex = 0
        End If
    End Sub
    Public Sub MarkChanged()
        If _MTShow Then
            Me.MTChanged = True
        Else
            Me.Changed = True
        End If
        Me.btUSave.Enabled = True
        Me.btUSave.Update()
        Me.btUClear.Enabled = True
        Me.btUClear.Update()
    End Sub
    Private Sub pgNProps_PropertyValueChanged(ByVal s As Object, ByVal e As System.Windows.Forms.PropertyValueChangedEventArgs) Handles pgNProps.PropertyValueChanged
        MarkChanged()
        If Not _MTShow Then
            If (Props.Tag = "SEG" Or Props.Tag = "PS") Then
                Dim pg As PropertyGrid = DirectCast(s, PropertyGrid)
                Dim tc As Integer = _MTCounts(Props.Type)
                If tc <> Props.MTCount Then
                    Props.MTCount = tc
                    pg.Validate()
                    pg.Update()
                    If tc > 0 Then
                        btMTiers.Enabled = True
                    Else
                        btMTiers.Enabled = False
                    End If
                End If
            Else
                btMTiers.Enabled = False
            End If
        End If
    End Sub

    Private Sub btUClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btUClear.Click
        If _MTShow Then
            CA.CLDS_ShowMTProperties(Me)
            Me.pgNProps.SelectedObject = Me.MTProps
            Me.pgNProps.Validate()
            Me.pgNProps.Update()
            Me.btUClear.Enabled = False
            Me.btUSave.Enabled = False
        Else
            CA.CLDS_SetNetworkProperties(Me)
            If Props.MTCount > 0 Then
                btMTiers.Enabled = True
            Else
                btMTiers.Enabled = False
            End If
        End If
    End Sub

    Private Sub btUSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btUSave.Click
        If _MTShow Then
            If Not CA.CLDS_SaveMTProperties(Me) Then
                Exit Sub
            End If
            _MTShow = False
            _MTChanged = False
            Me.Props.SetAttributes()
            Me.pgNProps.SelectedObject = Me.Props
            Me.btCopy.Enabled = True
            Me.btPaste.Enabled = True
            If Me.Changed Then
                btUClear.Enabled = True
                btUSave.Enabled = True
            Else
                btUClear.Enabled = False
                btUSave.Enabled = False
            End If
        Else
            CA.CLDS_UpdateMultiSegmentProps(Props)
            Props = Nothing
            Changed = False
            pgNProps.SelectedObject = Props
            pgNProps.Update()
            btUClear.Enabled = False
            btUSave.Enabled = False
            btDelete.Enabled = False
        End If
    End Sub

    Private Sub btJoin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btJoin.Click
        CA.CLDS_JoinNodes(Me)
    End Sub

    Private Sub btValidate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btValidate.Click
        CA.CLDS_ValidateNetwork(Me)
    End Sub

    Private Sub rbAddPS_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbAddPS.CheckedChanged
        btJoin.Enabled = True
        btFollow.Enabled = True
        cbIsMajor.Enabled = True
        cbIsMajor.Checked = True
    End Sub

    Private Sub rbAddDevice_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbAddDevice.CheckedChanged
        btJoin.Enabled = False
        btFollow.Enabled = False
        cbIsMajor.Enabled = False
    End Sub

    Private Sub rbAddNode_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbAddNode.CheckedChanged
        btJoin.Enabled = True
        btFollow.Enabled = True
        cbIsMajor.Enabled = True
    End Sub
    Private Sub tbDevID_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tbDevID.MouseDoubleClick
        CA.CLDS_SelectNode("", Me.tbDevID.Text, True)
    End Sub

    Private Sub btBreak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btBreak.Click
        CA.CLDS_BreakSegment(Me)
    End Sub

    Private Sub cbShowFill_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbShowFill.CheckedChanged
        If Me.cbShowFill.Checked Then
            Me.tbHFill.Enabled = True
        Else
            Me.tbHFill.Enabled = False
        End If
    End Sub

    Private Sub btMTiers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btMTiers.Click
        btUClear.Enabled = False
        btUSave.Enabled = False
        If _MTShow Then
            _MTShow = False
            Me.pgNProps.SelectedObject = Me.Props
            Me.btCopy.Enabled = True
            Me.btPaste.Enabled = True
            If Me.Changed Then
                btUClear.Enabled = True
                btUSave.Enabled = True
            End If
            btDelete.Enabled = True
        Else
            _MTShow = True
            If _MTChanged Then
                If Not Props.Type = MTProps.MTCode Then
                    CA.CLDS_ShowMTProperties(Me)
                    _MTChanged = False
                End If
            Else
                CA.CLDS_ShowMTProperties(Me)
            End If
            Me.pgNProps.SelectedObject = Me.MTProps
            Me.btCopy.Enabled = False
            Me.btPaste.Enabled = False
            If Me.MTChanged Then
                btUClear.Enabled = True
                btUSave.Enabled = True
            End If
            btDelete.Enabled = False
        End If
    End Sub


    Private Sub btCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btCopy.Click
        CA.CLDS_MakeNetworkDefaults(Me)
    End Sub

    Private Sub btPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btPaste.Click
        CA.CLDS_PasteNetworkDefaults(Me)
    End Sub

    Private Sub cbShowAnalysis_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbShowAnalysis.CheckedChanged
        Dim cb As CheckBox = TryCast(sender, CheckBox)
        If cb.Checked Then
            Me.cbShowSeg.Checked = False
            Me.cbShowFill.Checked = False
            Me.cbShowLock.Checked = False
            Me.cbShowApproved.Checked = False
            Me.cbShowRouted.Checked = False
            Me.btPClear.Enabled = False
        Else
            Dim av As String = Me.cbFArea.Text
            Dim sv As String = Me.cbFSeg.Text
            If av = "-" And sv = "-" Then
                Me.btPClear.Enabled = False
            Else
                Me.btPClear.Enabled = True
            End If
        End If
    End Sub

    Private Sub cbShowRouted_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbShowRouted.CheckedChanged, cbShowApproved.CheckedChanged, cbShowFill.CheckedChanged, cbShowLock.CheckedChanged, cbShowSeg.CheckedChanged
        Dim cb As CheckBox = TryCast(sender, CheckBox)
        If cb.Checked Then
            Me.cbShowAnalysis.Checked = False
        End If
    End Sub

    Private Sub cbFSeg_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbFSeg.SelectedIndexChanged
        Dim cb As ComboBox = TryCast(sender, ComboBox)
        If cb.Text = "-" Or cb.Text = "" Then
            Me.cbShowAnalysis.Enabled = False
            Me.cbShowAnalysis.Checked = False
        Else
            Me.cbShowAnalysis.Enabled = True
        End If
        Dim av As String = Me.cbFArea.Text
        Dim sv As String = Me.cbFSeg.Text
        If ((av = "-" Or av = "") And (sv = "-" Or sv = "")) Or Me.cbShowAnalysis.Checked Then
            Me.btPClear.Enabled = False
        Else
            Me.btPClear.Enabled = True
        End If
    End Sub

    Private Sub tcNetwork_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tcNetwork.SelectedIndexChanged
        Dim tc As TabControl = TryCast(sender, TabControl)
        If Not tc Is Nothing Then
            Dim tp As TabPage = tc.SelectedTab
            If tp.Name = "tpUpload" Then
                Me.rbScopeAll.Checked = False
                Me.rbScopeUpdates.Checked = True
            End If
        End If
    End Sub

    Private Sub cbFAType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbFAType.SelectedIndexChanged
        Dim cb As ComboBox = TryCast(sender, ComboBox)
        If Not cb Is Nothing Then
            Dim ay As String = Mid$(cb.Text, 1, 1)
            If ay = "0" Then
                Dim cArea As Collection = _CA.CLDS_PopulateCollection("AR", "AR", "CODE")
                _CA.CLDS_PopulateCB(Me.cbFArea, cArea, "-")
            Else
                Dim cArea As Collection = _CA.CLDS_PopulateCollection("AR", "A" & ay, "CODE")
                _CA.CLDS_PopulateCB(Me.cbFArea, cArea, "-")
            End If
        End If
    End Sub

    Private Sub cbFArea_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbFArea.SelectedIndexChanged
        Dim cb As ComboBox = TryCast(sender, ComboBox)
        If Not cb Is Nothing Then
            Dim av As String = Me.cbFArea.Text
            Dim sv As String = Me.cbFSeg.Text
            If ((av = "-" Or av = "") And (sv = "-" Or sv = "")) Or Me.cbShowAnalysis.Checked Then
                Me.btPClear.Enabled = False
            Else
                Me.btPClear.Enabled = True
            End If
        End If
    End Sub
End Class
